﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TextEditApp.Algorithm
{
    class AnotherDictionary
    {
        private List<string> words;
        private static AnotherDictionary dictionary = new AnotherDictionary();
        private AnotherDictionary()
        {
            words = new List<string>();
            try
            {
                // 创建一个 StreamReader 的实例来读取文件 
                // using 语句也能关闭 StreamReader
                using (StreamReader sr = new StreamReader("../../Algorithm/Txt/simple_dictionary.txt"))
                {
                    string line;

                    // 从文件读取并显示行，直到文件的末尾 
                    while ((line = sr.ReadLine()) != null)
                    {
                        words.Add(line.ToLower());
                    }
                }
            }
            catch (Exception exc)
            {
                // 向用户显示出错消息
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(exc.Message);
            }
        }

        /// <summary>
        /// 返回字典单例
        /// </summary>
        public static AnotherDictionary GetDictionary
        {
            get
            {
                return dictionary;
            }
        }

        /// <summary>
        /// 返回单词数组
        /// </summary>
        /// <returns></returns>
        public string[] GetWords()
        {
            return this.words.ToArray();
        }
    }
}
